package com.siwei.mes.service.experiment.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.entity.experiment.ExperimentSampleTestProject;
import com.siwei.mes.mapper.experiment.ExperimentSampleTestProjectMapper;
import com.siwei.mes.service.experiment.ExperimentSampleTestProjectService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

/**
 * 抽样样品试验项目(ExperimentSampleTestProject)表服务实现类
 *
 * @author linzi
 * @since 2023-12-31 20:37:12
 */
@Service
public class ExperimentSampleTestProjectServiceImpl implements ExperimentSampleTestProjectService {
    @Resource
    private ExperimentSampleTestProjectMapper experimentSampleTestProjectMapper;

    @Override
    public Long create(ExperimentSampleTestProject entity) {
        experimentSampleTestProjectMapper.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public void update(ExperimentSampleTestProject entity) {
        ExperimentSampleTestProject experimentSampleTestProject = experimentSampleTestProjectMapper.selectByPrimaryKey(entity.getId());
        assertTrue(experimentSampleTestProject == null, "抽样样品试验项目信息不存在");
        experimentSampleTestProjectMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void delete(Long id) {
        ExperimentSampleTestProject experimentSampleTestProject = experimentSampleTestProjectMapper.selectByPrimaryKey(id);
        assertTrue(experimentSampleTestProject == null, "抽样样品试验项目信息不存在");
        experimentSampleTestProjectMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<ExperimentSampleTestProject> getPage(PageQuery<ExperimentSampleTestProject, ExperimentSampleTestProject> query) {
        ExperimentSampleTestProject searchParam = query.getParams();
        return PageHelper.startPage(query.getPageNum(), query.getPageSize())
                .doSelectPageInfo(() -> experimentSampleTestProjectMapper.getList(searchParam));
    }

    @Override
    public ExperimentSampleTestProject loadById(Long id) {
        return experimentSampleTestProjectMapper.loadById(id);
    }

    @Override
    public List<ExperimentSampleTestProject> getAll(ExperimentSampleTestProject entity) {
        return experimentSampleTestProjectMapper.getList(entity);
    }
}
